<!DOCTYPE html>
<html xmlns:shiro="http://www.w3.org/1999/xhtml">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>结算信息</title>
    <link th:replace="comm/header :: header">
    <style>

    </style>
    <script type="text/javascript">

        var money=0;
        function formatEdit(val, row, index) {
            var str = '';
            money+=row.payment;
            if ($("#applypaymentupdate").length > 0) {
                if (row.piaostatus == 0 && row.paystatus == 1) {
                    str += $.formatString('<a  href="javascript:void(0)" class="applypayment-easyui-linkbutton-edit-1 primary l-btn l-btn-small l-btn-plain" onclick="searchPayerFun(\'{0}\');" >去开票</a>', index);
                    str += $.formatString('<a  href="javascript:void(0)" class="applypayment-easyui-linkbutton-edit-2 info l-btn l-btn-small l-btn-plain" onclick="showDetail(\'{0}\');" >趟数明细</a>', index);
                } else {
                    str += $.formatString('<a  href="javascript:void(0)" class="applypayment-easyui-linkbutton-edit-2 info l-btn l-btn-small l-btn-plain" onclick="showDetail(\'{0}\');" >趟数明细</a>', index);
                }
            }
            $("#money").html(money);
            return str;
        }

        function formatterName(value, row) {
            return row.captain.cname;
        }

        function formatterPhone(value, row) {
            return row.captain.phone;
        }

        function formatterBank(value, row) {
            return row.captain.cdepositBank;
        }

        function formatterAccount(value, row) {
            return row.captain.account;
        }

        function formatter(value, row, index) {
            if (row.paystatus == 0) {
                return '未支付';
            } else {
                return '已支付';
            }
        }

        function year() {
            var year = $('input[name="year"]').val();
            var mouth = $('input[name="mouth"]').val();
            var day = $('input[name="day"]').val();
            $('input[name="mouth"]').val('');
            $('input[name="day"]').val('');
            fa(year, mouth, day);
        }

        function mouth() {
            var year = $('input[name="year"]').val();
            var mouth = $('input[name="mouth"]').val();
            var day = $('input[name="day"]').val();
            if (year == null || year == "") {
                alert("请先输入年份");
                $('input[name="mouth"]').val('');
            }
            fa(year, mouth, day);
        }

        function day() {
            var year = $('input[name="year"]').val();
            var mouth = $('input[name="mouth"]').val();
            var day = $('input[name="day"]').val();
            if(year==null||year==""){
                alert("请先输入年份");
                $('input[name="day"]').val('');
            }else if(mouth==""||mouth==null){
                alert("请输入月份");
                $('input[name="day"]').val('');
            }
            fa(year, mouth, day);
        }

        function fa(year, mouth, day) {
            money=0;
            $("#dg").datagrid('load', {
                "year": year,
                "mouth":mouth,
                "day":day
            });
        }

        function formatter1(value, row, index) {
            if (row.piaostatus == 0) {
                return '未开票';
            } else {
                return '已开票';
            }
        }

        function searchApplypayment() {
            money=0;
            $("#dg").datagrid('load', {
                "name": $("#s_CaptainName").val()
            });
        }

        function saveBillNum() {
            var billNUmsave = $("#billNUmsave").val()
            $("#sbiSettlebillnum").val(billNUmsave)
            $("#dlgBillNum").dialog("close");
            var id = $("#id").val();
            var payment = $("#payment").val();
            $.messager.confirm("系统提示", "确认提交单号?", function (r) {
                if (r) {
                    $("#fm").form("submit", {
                        url: "/fin/jie/dan",
                        data: {id: id, payment: payment},
                        onSubmit: function () {
                            return $(this).form("validate");
                        },
                        success: function (result) {
                            var result = eval('(' + result + ')');
                            if (result.flag) {
                                message("已开票");
                                $("#dlg").dialog("close");
                                $("#dg").datagrid("reload");
                            } else {
                                message(result.info);
                            }
                        }
                    });
                }
            })
        }

        function searchPayerFun(index) {
            $("#dg").datagrid('selectRow', index);
            var selectedRows = $("#dg").datagrid("selectRow");
            var row = $("#dg").datagrid("getSelected");
            $("#dlg").dialog("open").dialog("setTitle", "结算信息明细");
            $('input[name="cname"]').val(row.captain.cname);
            $('input[name="phone"]').val(row.captain.phone);
            $('input[name="account1"]').val(row.captain.account);
            $("#fm").form("load", row);
        }
        function clone() {
            money=0;
        }

        //查询趟数明细
        function showDetail(index) {
            $("#dg").datagrid('selectRow', index);
            var selectedRows = $("#dg").datagrid("selectRow");
            var row = $("#dg").datagrid("getSelected");
            var caphonenum = row.capTelephone
            var id = row.id;
            console.log(caphonenum)
            $('#dgdetail').datagrid('load', {
                id: id,
            });
            $("#showdetail").dialog("open").dialog("setTitle", "趟数明细");
        }
    </script>
</head>
<!--<shiro:hasPermission name="settlebill:billing">
    <input type="hidden" id="settlebillbilling"/>
</shiro:hasPermission>-->


<body style="margin: 1px">
<!--明细申请页面展示-->
<div id="showdetail" class="easyui-dialog" style="width: 800px;height: 500px;padding: 10px 20px"
     closed="true" buttons="#showdetail-buttons">
    <table id="dgdetail" class="easyui-datagrid"
           fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
           url="/fin/qing/list" fit="true" toolbar="#tb" method="get">
        <thead>
        <th field="id" width="20" align="center" hidden>编号</th>
        <th field="idcard" width="20" align="center">车牌号</th>
        <th field="ctotal" width="20" align="center">趟数</th>
        <th field="price" width="20" align="center">单价</th>
        <th field="payment" width="20" align="center">总价</th>
        </thead>
    </table>



</div>
<shiro:hasPermission name="settle:manage:ticket">
<input type="hidden" id="applypaymentupdate"/>
</shiro:hasPermission>

<table id="dg" title="结算信息管理" class="easyui-datagrid"
       fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
       url="/fin/jie/listAll" fit="true" toolbar="#tb" method="get">
    <thead>
    <th field="id" width="20" align="center" hidden>编号</th>
    <th field="cname" width="25" align="center" formatter="formatterName">队长姓名</th>
    <th field="eid" width="50" align="center">企业id</th>
    <th field="payment" width="30" align="center">应付款</th>
    <th field="ctotal" width="15" align="center">趟数</th>
    <th field="cdepositBank" width="30" align="center" formatter="formatterBank">队长开户行</th>
    <th field="phone" width="30" align="center" formatter="formatterPhone">队长手机</th>
    <th field="account" width="35" align="center" formatter="formatterAccount">队长账户</th>
    <th field="paystatus" width="20" align="center" formatter="formatter">支付状态</th>
    <th field="piaostatus" width="20" align="center" formatter="formatter1">开票状态</th>
    <th field="piaonum" width="40" align="center" hidden>票据单号</th>
    <th field="shentime" width="65" align="center">审批时间</th>
    <th field="op" width="90" align="center" formatter="formatEdit">操作</th>
    </thead>
</table>


<div id="tb">
    &nbsp;队长姓名：&nbsp;<input class="easyui-textbox" id="s_CaptainName"
                            data-options="iconCls:'fa fa-file',iconAlign:'left'" prompt="请输入队长名称" size="20"/>
    <a href="javascript:searchApplypayment()" class="easyui-linkbutton primary" iconCls="icon-search"
       plain="true">搜索</a>
    <input id="year" name="year" type="text" onchange="year()">年<input id="mouth" name="mouth" type="text"
                                                                       onchange="mouth()">月<input id="day" name="day"
                                                                                                  type="text"
                                                                                                  onchange="day()">日 金额:<label
        id="money"></label>
</div>


<div id="dlg" class="easyui-dialog" style="width: 450px;height: 350px;padding: 10px 20px"
     closed="true" buttons="#dlgBillNum-buttons">
    <form id="fm" method="post">
        <input type="hidden" id="id" name="id">
        <table cellspacing="8px">
            <tr>
                <td>队长姓名：</td>
                <td>
                    <input type="text" id="cname" name="cname" class="easyui-validatebox" required="true" readonly/>
                </td>
            </tr>
            <tr>
                <td>队长手机：</td>
                <td>
                    <input type="text" id="phone" name="phone" class="easyui-validatebox" required="true"
                           readonly/>
                </td>
            </tr>
            <tr>
                <td>趟数：</td>
                <td>
                    <input type="text" id="ctotal" name="ctotal" class="easyui-validatebox"
                           required="true" readonly/>
                </td>
            </tr>
            <tr>
                <td>应付款：</td>
                <td>
                    <input type="text" id="payment" name="payment" class="easyui-validatebox" required="true"
                           readonly/>
                </td>
            </tr>
            <tr>
                <td>队长账户：</td>
                <td>
                    <input type="text" id="account" name="account1" class="easyui-validatebox" required="true"
                           readonly/>
                </td>
            </tr>
        </table>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:openRemark()" class="easyui-linkbutton" iconCls="icon-edit" style="width:95px">填写单号</a>
    <a href="javascript:closePayDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>

<div id="dlgBillNum-buttons">
    <a href="javascript:saveBillNum()" class="easyui-linkbutton" iconCls="icon-ok">确认</a>
    <a href="javascript:closeBillNumDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>


<div id="uploadonlineinfo" class="easyui-dialog" style="width:380px;padding:10px 40px" closed="true">
    <form id="fam" method="post" enctype="multipart/form-data">
        <input type="hidden" id="flag" name="flag">
    </form>
</div>
<script type="text/javascript">
    $(function () {
        $("#dg").datagrid({
            onLoadSuccess: function (data) {
                $('.applypayment-easyui-linkbutton-edit-1').linkbutton({
                    text: '去开票',
                    plain: true,
                    iconCls: 'icon-edit'
                });
                $('.applypayment-easyui-linkbutton-edit-2').linkbutton({
                    text: '趟数明细',
                    plain: true,
                    iconCls: 'icon-edit'
                });
                $('#dg').datagrid('fixRowHeight');
                clone();
            }
        });
    })
</script>
</body>
</html>